package com.zf.test;

import java.util.Scanner;

/**
 * @author Li
 * @Date 2023/4/15 9:27
 */
public class Login {
    public static void main(String[] args) {
        String username = "admin";
        String password = "12345";
        int time = 0;
        while (true) {
            LoginScanner loginScanner = new LoginScanner();
            String name = loginScanner.getString("请输入用户名:");
            String pass = loginScanner.getString("请输入密码:");
            if (judge(username, name, password, pass)) {
                return;
            }
            time++;
            if (time>=3){
                System.out.println("三次登录失败！");
                return;
            }
        }
    }

    private static boolean judge(String username, String name, String pass, String password) {
        if (username.equals(name)) {
            if (password.equals(pass)) {
                System.out.println("登录成功");
                return true;
            } else {
                System.out.println("密码错误！");
                return false;
            }
        } else {
            System.out.println("用户名错误！");
           return false;
        }

    }
}
